cmake_minimum_required(VERSION 3.22.3)
project(langge_vdr)
#3rd

set(CMAKE_CXX_STANDARD 17)

set(BUILD_SHARED_LIBS FALSE)

include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
include_directories(${CMAKE_CURRENT_LIST_DIR}/include/osapi)
include_directories(${CMAKE_CURRENT_LIST_DIR}/include/3rd)
include_directories(${CMAKE_CURRENT_LIST_DIR}/include/3rd/eigen3)

include_directories(${CMAKE_CURRENT_LIST_DIR}/include/3rd/geos/include)
include_directories(${CMAKE_CURRENT_LIST_DIR}/include/3rd/json)
include_directories(${CMAKE_CURRENT_LIST_DIR}/include/common/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/include/common/log)
include_directories(${CMAKE_CURRENT_LIST_DIR}/include/dm)

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
    add_compile_options(/Zc:__cplusplus)
    set(CMAKE_CXX_STANDARD 17)

    if("${CMAKE_BUILD_TYPE}" STREQUAL "")
        set(CMAKE_BUILD_TYPE Debug)
    endif()

    link_directories(${LIBRARY_OUTPUT_PATH}/ ${LIBRARY_OUTPUT_PATH}/${CMAKE_BUILD_TYPE}/)
endif()

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
    message("CMAKE_VS_PLATFORM_NAME: " ${CMAKE_VS_PLATFORM_NAME})
    set(EXECUTABLE_OUTPUT_PATH
            ${CMAKE_CURRENT_LIST_DIR}/bin/${CMAKE_SYSTEM_NAME}/${CMAKE_VS_PLATFORM_NAME})
    set(LIB_3RD_OUTPUT_PATH
            ${CMAKE_CURRENT_LIST_DIR}/lib/3rd/${CMAKE_SYSTEM_NAME}/${CMAKE_VS_PLATFORM_NAME})
    set(LIBRARY_OUTPUT_PATH
            ${CMAKE_CURRENT_LIST_DIR}/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_VS_PLATFORM_NAME})
else()
    message("CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR})
    set(EXECUTABLE_OUTPUT_PATH
            ${CMAKE_CURRENT_LIST_DIR}/bin/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR})
    set(LIB_3RD_OUTPUT_PATH
            ${CMAKE_CURRENT_LIST_DIR}/lib/3rd/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR})
    set(LIBRARY_OUTPUT_PATH
            ${CMAKE_CURRENT_LIST_DIR}/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR})
endif()

# 链接目录
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
    link_directories(${CMAKE_CURRENT_LIST_DIR}/lib/3rd/Windows)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
    message("ANDROID_ABI:" ${ANDROID_ABI})
    if ("${ANDROID_ABI}" STREQUAL "arm64-v8a")
        link_directories(${CMAKE_CURRENT_LIST_DIR}/lib/3rd/openssl/Android/arm64-v8a)
        link_directories(${CMAKE_CURRENT_LIST_DIR}/lib/3rd/curl/Android/arm64-v8a)
    elseif ("${ANDROID_ABI}" STREQUAL "armeabi-v7a")
        link_directories(${CMAKE_CURRENT_LIST_DIR}/lib/3rd/openssl/Android/armeabi-v7a)
        link_directories(${CMAKE_CURRENT_LIST_DIR}/lib/3rd/curl/Android/armeabi-v7a)
    endif()
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
    message("ARCHS: ${ARCHS}")
    link_directories(${CMAKE_CURRENT_LIST_DIR}/lib/3rd/openssl/ios/${ARCHS})
    link_directories(${CMAKE_CURRENT_LIST_DIR}/lib/3rd/curl/ios/${ARCHS})
endif()


if(WIN32)
    # add_compile_options(/W4)
    add_compile_options(/wd4819)
    add_compile_options(/utf-8)
elseif(IOS)
    add_definitions(-DIOS)

    set(LIB_3RD_OUTPUT_PATH
            ${CMAKE_CURRENT_LIST_DIR}/lib/${CMAKE_BUILD_TYPE}-iphoneos/3rd)
    set(LIBRARY_OUTPUT_PATH
            ${CMAKE_CURRENT_LIST_DIR}/lib/${CMAKE_BUILD_TYPE}-iphoneos)
elseif(ANDROID)
    add_definitions(-DANDROID
            # -DSTBI_NEON
            )
    # message(FATAL_ERROR "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
    set(LIB_3RD_OUTPUT_PATH
            ${CMAKE_CURRENT_LIST_DIR}/lib/3rd/${CMAKE_SYSTEM_NAME}/${CMAKE_ANDROID_ARCH_ABI}/${CMAKE_BUILD_TYPE})
    # message(FATAL_ERROR "LIB_3RD_OUTPUT_PATH = ${LIB_3RD_OUTPUT_PATH}")
    set(LIBRARY_OUTPUT_PATH
            ${CMAKE_CURRENT_LIST_DIR}/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_ANDROID_ARCH_ABI})


else()
    set(LINUX TRUE)
endif()

# 增加mac ios 平台库
if("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
    set(CMAKE_EXE_LINKER_FLAGS "-framework Cocoa -framework AppKit -framework CoreData -framework Foundation")
endif()
MESSAGE("LIBRARY_OUTPUT_PATH:" ${LIBRARY_OUTPUT_PATH})
MESSAGE(${LIB_3RD_OUTPUT_PATH})
link_directories(${LIBRARY_OUTPUT_PATH})
link_directories(${LIB_3RD_OUTPUT_PATH})
link_directories(${LIB_3RD_OUTPUT_PATH}/Debug)
link_directories(${LIB_3RD_OUTPUT_PATH}/Release)

# 构建工程
add_subdirectory(src)
add_executable(vdrDemo main.cpp include/loc_types.h include/algorithm/vdr_config.h include/algorithm/VdrCore.cpp include/algorithm/VdrCore.hpp )
target_link_libraries(vdrDemo PRIVATE vdr geos log4cplus osapi pthread)